package com.moli.lumpSugar.chat.service.strategy.msg;



import com.moli.lumpSugar.common.exception.CommonErrorEnum;
import com.moli.lumpSugar.common.utils.AssertUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * @program: LumpSugarChat
 * @description: 消息类型工厂
 * @author: zhangjt
 * @create: 2024-10-31 15:26
 **/
public class MsgHandlerFactory {
    private static final Map<Integer, AbstractMsgHandler> STRATEGY_MAP = new HashMap<>();
    public static void register(Integer code, AbstractMsgHandler strategy) {
        STRATEGY_MAP.put(code, strategy);
    }
    public static AbstractMsgHandler getStrategy(Integer code) {
        AbstractMsgHandler strategy = STRATEGY_MAP.get(code);
        AssertUtil.isNotEmpty(strategy, CommonErrorEnum.PARAM_VALID);
        return strategy;
    }
}
